﻿namespace GCC.Container.Abstracts
{
    /// <summary>
    /// 入口抽象
    /// </summary>
    public abstract class AbsEntrance
    {
        /// <summary>
        /// 数据库管理实例
        /// </summary>
        public static IDBManager? DBManager { get; private set; }

        /// <summary>
        /// 日志提供器
        /// </summary>
        public static AbsGCCLoggerProvider? GCCLoggerProvider { get; private set; }

        /// <summary>
        /// 服务名称
        /// </summary>
        /// <returns></returns>
        public abstract string Name();

        /// <summary>
        /// 需要的容器版本最低
        /// </summary>
        /// <returns></returns>
        public abstract Version NeedsApiContainerVersion();

        /// <summary>
        /// 当获取到数据库上下文后会调用
        /// </summary>
        public abstract void OnGetDBInstance();

        /// <summary>
        /// 设置数据库实例
        /// </summary>
        /// <param name="instance"></param>
        public void SetDBInstance(IDBManager instance)
        {
            DBManager = instance;
            this.OnGetDBInstance();
        }

        /// <summary>
        /// 当系统启动完成后会触发,给予一次当前的系统上下文
        /// </summary>
        /// <param name="context"></param>
        public abstract void OnSystemStarted(AbsGCCContext context);

        /// <summary>
        /// 设置日志提供器
        /// </summary>
        /// <param name="provider">提供器实例</param>
        public void SetLoggerProvider(AbsGCCLoggerProvider provider)
        {
            GCCLoggerProvider = provider;
        }

        /// <summary>
        /// 当前程序集是否是发布版本
        /// </summary>
        /// <returns></returns>
        public abstract bool IsRelease();

        /// <summary>
        /// 系统将要关闭
        /// </summary>
        public abstract void SystemTryShutDown();
    }
}
